<template>


  <div>

    <!--  查询-->
    <el-card>

      <el-form inline label-width="90px" size="mini" class="demo-form-inline">


        <el-form-item label="标题">
          <el-input placeholder="请输入标题" v-model.trim="queryParam.title" clearable size="mini"></el-input>
        </el-form-item>
        <el-form-item label="标签名">
          <el-input placeholder="请输入标签名" v-model.trim="queryParam.tagsName" clearable size="mini"></el-input>
        </el-form-item>
        <el-form-item label="标签">
          <el-select v-model="queryParam.tags" placeholder="请选择" clearable filterable >
            <el-option
              v-for="item in dict1015"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="queryParam.status" placeholder="请选择" clearable  >
            <el-option key="1" label="过时" :value="1"/>
            <el-option key="2" label="发布" :value="2"/>
          </el-select>
        </el-form-item>
        <el-form-item label="面向人群">
          <el-select v-model="queryParam.audience" placeholder="请选择" clearable filterable >
            <el-option
              v-for="item in dict1014"
              :key="item.id"
              :label="item.name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>


        <el-form-item>
          <el-button type="success" size="mini" @click="getListPage">查询</el-button>
          <el-button type="info" size="mini" @click="resetQuery">重置</el-button>
          <el-button type="warning" size="mini" @click="openSaveBefore">新增</el-button>
        </el-form-item>

      </el-form>

    </el-card>





    <!--列表-->
    <el-card style="margin-top: 10px">

      <el-table
          :data="tableData"
          max-height="650px"
          height="650px"
          style="width: 100%">


        <el-table-column prop="title" label="标题"/>
        <el-table-column prop="tagsName" label="标签" width="80"/>
        <el-table-column label="状态" width="80">
          <template slot-scope="scope">
            <el-tag size="mini" type="info" v-if="scope.row.status === 1">过时</el-tag>
            <el-tag size="mini" type="success" v-else-if="scope.row.status === 2">发布</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="readNum" label="阅读数" width="80">
          <template slot-scope="scope">
            <el-tag size="mini">{{scope.row.readNum}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="commentNum" label="评论数" width="80">
          <template slot-scope="scope">
            <el-tag size="mini">{{scope.row.commentNum}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="score" label="得分" width="150">
          <template slot-scope="scope">
            <el-rate disabled v-model="scope.row.score" />
          </template>
        </el-table-column>
        <el-table-column prop="audienceName" label="面向人群" width="100"/>



        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <el-button @click="openViewBefore(scope.row)" type="text" size="small"><i class="el-icon-view"></i>查看</el-button>
            <el-button @click="openUpdBefore(scope.row)" type="text" size="small"><i class="el-icon-edit"></i>编辑</el-button>
            <el-button @click="delTips(scope.row)" type="text" size="small"><i class="el-icon-delete"></i>删除</el-button>
          </template>
        </el-table-column>

      </el-table>


      <!--分页部分-->
      <el-pagination
          style="width:33%; margin-right:10px; margin-top:10px;"
          background
          layout="total, prev, pager, next, jumper"
          @current-change="pageCurrentChange"
          :page-size="pageConfig.size"
          :current-page="pageConfig.current"
          :pager-count="5"
          :total="pageConfig.total">
      </el-pagination>

    </el-card>

    <OpsKnowledgeSaveUpd  ref="OpsKnowledgeSaveUpdRef" @getListPage="getListPage"/>

  </div>

</template>


<script>

import http from '@/utils/http'
import OpsKnowledgeSaveUpd  from './OpsKnowledgeSaveUpd.vue'


export default {
  name: "OpsKnowledgeList",
  components: {
    OpsKnowledgeSaveUpd,
  },
  data() {
    return {
      // 查询参数
      queryParam: {
        title: null,
        tags: null,
        status: null,
        tagsName: null,
        audience: null,
      },
      // 分页参数
      pageConfig: {
        // 每页记录数
        size: 20,
        // 当前页码
        current: 1,
        // 总记录数
        total: 0,
      },
      // 表格数据
      tableData: [],
      // 知识库-面向人群
      dict1014: [],
      // 知识库-标签
      dict1015: [],
    }
  },
  methods: {
    /**
     * 分页查询字典-知识库-标签
     */
    getDictListPage1015(){
      http.post("/opsSysDict/getListPage", {
        // 分页参数
        current: 1,
        size: 9999,
        sysDictGroupId: "1958194955357315072",
      }).then(response => {
        let res = response.data;
        // 分页数据
        let data = res.data;
        // 处理数据
        this.dict1015 = data.records

      }).catch(error => {
        this.$message.error(error.message);
      })
    },
    /**
     * 分页查询字典-知识库-面向人群
     */
    getDictListPage1014(){
      http.post("/opsSysDict/getListPage", {
        // 分页参数
        current: 1,
        size: 9999,
        sysDictGroupId: "1958194298650943488",
      }).then(response => {
        let res = response.data;
        // 分页数据
        let data = res.data;
        // 处理数据
        this.dict1014 = data.records

      }).catch(error => {
        this.$message.error(error.message);
      })
    },
    /**
     * 打开保存的弹框
     */
    openSaveBefore() {
      this.$refs.OpsKnowledgeSaveUpdRef.init('save', null)
    },
    /**
     * 查看之前触发
     * @param obj 这一行数据
     */
    openViewBefore(obj){
      // 打开新标签
      let routeData = this.$router.resolve(({
        path: '/toKnowledgeDetailed', // path 要跳转的路由地址
        // query 要传递的参数
        query: {
          id: obj.id,
        }
      }))
      window.open(routeData.href,'_blank')
    },
    /**
     * 打开修改之前的的弹出框
     * @param obj 修改的值
     */
    openUpdBefore(obj) {
      this.$refs.OpsKnowledgeSaveUpdRef.init('upd', obj)
    },
    /**
     * 删除之前的提示框
     * @param obj 要删除的数据
     */
    delTips(obj) {
      this.$confirm('是否执行删除, 删除后无法恢复，是否继续?', '提示', {
        confirmButtonText: '确定删除',
        cancelButtonText: '取消删除',
        type: 'warning'
      }).then(() => {
        // 确定删除
        this.delOpsKnowledge(obj)

      }).catch(() => {
        // 取消删除
      });
    },
    /**
     * 删除
     * @param obj 要删除的数据
     */
    delOpsKnowledge(obj) {
      http.post("opsKnowledge/delOpsKnowledge", {
        id: obj.id,
      }).then(response => {
        let res = response.data;
        this.getListPage()
        this.$message.success("删除成功");

      }).catch(error => {
        this.$message.error (error.message)
      })
    },
    /**
     * 分支分页查询列表
     */
    getListPage() {
      this.queryParam.current = this.pageConfig.current
      this.queryParam.size = this.pageConfig.size
      http.post("/opsKnowledge/getListPage", this.queryParam).then(response => {
        let res = response.data;
        // 分页数据
        let data = res.data;
        this.pageConfig.total = data.total;
        this.pageConfig.current = data.current;
        this.pageConfig.size = data.size;
        // 表格数据
        this.tableData = data.records

      }).catch(error => {
        this.$message.error (error.message);
      })
    },
    /**
     * 分页被改变的时候
     * @param value 当前页
     */
    pageCurrentChange(value) {
      this.pageConfig.current = value
      this.getListPage()
    },
     /**
     * 重置查询条件
     */
    resetQuery() {
      this.queryParam = {
        title: null,
        tags: null,
        status: null,
        tagsName: null,
        audience: null,
      }
    },
     /**
     * 分页前重置分页参数
     */
    getPageListBefore() {
      this.pageConfig.current = 1
      this.getListPage()
    },
  },
  // 进入马上执行
  mounted() {
    this.getListPage()
    this.getDictListPage1015()
    this.getDictListPage1014()
    this.$store.commit ('navigationListChange', [
      {name: '知识中心', url: '/toOpsKnowledgeList', query: {}},
    ])
  },
}
</script>

<style scoped>

</style>

